package leetcode;

import java.util.*;

public class lc77 {
    public static void main(String[] args) {
        System.out.println(combine(4,2));
    }
    public static List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> ans = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        if(k > n)
            return ans;
        backTrack(n, k, ans, path, 1);
        return ans;
    }
    public static void backTrack(int n, int k, List<List<Integer>> ans, List<Integer> path, int index){
        if(path.size() == k){
            ans.add(new ArrayList<>(path));
            return;
        }
        for (int i = index; i <= n; i++) {
                path.add(i);
                backTrack(n, k,  ans, path, i + 1);
                path.remove(path.size() - 1);
        }
    }
}
